var mailServerData = [];
var deleteflag ;

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
    $("#update").show();
    $("#save").hide();
    search();
    setTimeout(hideLoading, 500);
})
function search() {
	$.ajax({
		type : 'post',
		data : $("#serverMaintenance").serialize(),
		url : 'searchMailServerMaintenance',
		dataType : 'json',
		success : function(data) {
			$("#mailServer").val(data.mailServerHost);
			$("#serverPort").val(data.mailServerPort);
		    $("#addresser").val(data.userName);
		    $("#addresserMail").val(data.fromAddress);
		    $("#mailPassword").val(data.password);
		},
		error : function(data) {
			if (data.status == "403" && data.statusText == "Forbidden") {
				showMessge("您没有操作权限!");
			} else {
				showMessge("查询失败!");
			}
		},
		timeout: function(data){
			showMessge("操作超时！");
		}
	})
}
function update() {
    $("#mailServer").attr("disabled", false);
    $("#serverPort").attr("disabled", false);
    $("#addresser").attr("disabled", false);
    $("#addresserMail").attr("disabled", false);
    $("#mailPassword").attr("disabled", false);
    $("#receiverMail").attr("disabled", false);
    $("#save").show();
    $("#update").hide();
}
function save() {
    $("#mailServer").attr("disabled", true);
    $("#serverPort").attr("disabled", true);
    $("#addresser").attr("disabled", true);
    $("#addresserMail").attr("disabled", true);
    $("#mailPassword").attr("disabled", true);
    $("#receiverMail").attr("disabled", true);
    $("#update").show();
    $("#save").hide();
    var mailServer = $("#mailServer").val();
	var serverPort = $("#serverPort").val();
	var addresser = $("#addresser").val();
	var addresserMail = $("#addresserMail").val();
	var mailPassword = $("#mailPassword").val();
	var receiverMail = $("#receiverMail").val();
	showLoading();
	$.ajax({
		type : "POST",
		url : 'updateMailServerMaintenance',
		data : {
			mailServerHost : mailServer,
			mailServerPort : serverPort,
			userName : addresser,
			fromAddress : addresserMail,
			password : mailPassword,
		},
		dataType : 'json',
		success: function(data){
			setTimeout(hideLoading, 500);
			var result = data && data.result;
			if (result == "Success") {
				showMessge("修改成功");
				search();
			} else if (result == "NotFound") {
				showMessge("修改失败");
			} else {
				showMessge("修改异常");
			}
        },
        error : function(data) {
            setTimeout(hideLoading, 500);
            if (data.status == "403" && data.statusText == "Forbidden") {
                showMessge("您没有操作权限!");
            } else {
                showMessge("操作失败!");
            }
        },
        timeout: function(data){
			setTimeout(hideLoading, 500);
			showMessge("操作超时！");
		}
	});
	formReset("serverMaintenance");
}

